/*
"The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.

The Original Code is ReportSheet.

The Initial Developer of the Original Code is Amarnath Chatterjee.
Portions created by Amarnath Chatterjee are Copyright (C). All Rights Reserved.

Contributor(s): Amarnath Chatterjee.
*/

package Reporting
{
	import flash.events.Event;
	
	import mx.controls.Alert;
	import Reporting.Utils.CommonUtils;
	
	//This class can also be used in events.
	public class CellInfo extends Event 
	{
		//These variables are used when CellInfo is thrown as an event.
		public static var CELLDATA_UPDT : String = "CellDataUpdated";
		public var IsCellDataUpdate : Boolean;
		public var IsStyleUpdated : Boolean;		
		
		//Cell Information holders.
		public var row : int = 0;
		public var col : int = 0;
		public var data : String = "";
		public var mathExprn : String = "";
		public var lock : Boolean = false;
		
		//Cell Style Holders.
		public var backgroundColor : String = "0xffffff";
		public var fontColor : String = "0x0B333C";
		public var fontStyle : String = CellRenderer.FONTNORMAL;
		public var fontBold : String = CellRenderer.FONTNORMAL;
		
 
		public function CellInfo(bubblingEvent : Boolean = true, cancelableEvent : Boolean = false)
		{
			super(CELLDATA_UPDT, bubblingEvent, cancelableEvent);
		}
		
		//This is a special Lazy initialization, which can parse the xml and setup all contents.
		//The parsing technique is based on the formation of our xml format. Have to streamline stuffs in
		//future.
		public function InitCellInfo(r : int, c : int, ipxml : XML) : void
		{
			row = r;
			col = c;
			var colId : String = ReportSheet.COL_IDENTIFIER+c; 
			var maxrows : int = parseInt(ipxml.root.row.length());
			var maxcols : int = parseInt(ipxml.root.row[0].children().length());
			
			if(r >= maxrows || c >= maxcols)
			{
				throw Error("Invalid r,c : CellInfo");
			}
			
			data = ipxml.root.row[r].child(colId)[0];
			if ( ipxml.root.row[r].child(colId)[0].attributes().length() != 0)
			{
				mathExprn = ipxml.root.row[r].child(colId)[0].@[ReportSheet.MATH_EXPRN_ATTR];
				if(ipxml.root.row[r].child(colId)[0].@[ReportSheet.LOCK_EXPRN_ATTR] != undefined)
				{
					lock = CommonUtils.parseBoolean(ipxml.root.row[r].child(colId)[0].@[ReportSheet.LOCK_EXPRN_ATTR]);
				}
			
				backgroundColor = ipxml.root.row[r].child(colId)[0].@[CellRenderer.BGCOLOR];
				fontColor = ipxml.root.row[r].child(colId)[0].@[CellRenderer.FONTCOLOR];
				fontStyle = ipxml.root.row[r].child(colId)[0].@[CellRenderer.FONTSTYLE];
				fontBold = ipxml.root.row[r].child(colId)[0].@[CellRenderer.FONTWEIGHT];
			}
		}
		
		public function ShowCellInformation() : void
		{
			var InfoStr : String = "";
			InfoStr += "\nrow = "+ row;
			InfoStr += "\ncol = "+ col;
			InfoStr += "\ndata = "+ data;
			InfoStr += "\nbgCol = "+ backgroundColor;
			InfoStr += "\nfontColor = "+ fontColor;
			InfoStr += "\nfontStyle = "+ fontStyle;
			InfoStr += "\nfontBold = "+ fontBold;
			InfoStr += "\nmathExpr = "+mathExprn;
			Alert.show(InfoStr);
		}
		
		public function CompareIndices(ci : CellInfo) : Boolean
		{
			if( ci.row == row && ci.col == col)
				return true;
			else
				return false;
		}
	}
}
